package jblip.base.resources;

import jblip.resources.Subscription;
import jblip.resources.Transport;
import jblip.resources.User;

class BaseSubscription implements Subscription {
  private static final long serialVersionUID = 1L;

  private final Transport transport_;

  private final String tracked_user_name_;
  private final String tracking_user_name_;

  private final User tracked_user_;
  private final User tracking_user_;

  BaseSubscription(final Transport transport, final String tracked_path,
      final String tracking_path, final User tracked_user,
      final User tracking_user) {
    this.transport_ = transport;
    this.tracked_user_ = tracked_user;
    this.tracking_user_ = tracking_user;
    this.tracked_user_name_ = tracked_path.substring(tracked_path
        .lastIndexOf('/') + 1);
    this.tracking_user_name_ = tracking_path.substring(tracking_path
        .lastIndexOf('/') + 1);
  }

  @Override
  public User getTrackedUser() {
    return tracked_user_;
  }

  @Override
  public String getTrackedUserName() {
    if (tracked_user_name_ == null) {
      return tracked_user_.getLogin();
    } else {
      return tracked_user_name_;
    }
  }

  @Override
  public User getTrackingUser() {
    return tracking_user_;
  }

  @Override
  public String getTrackingUserName() {
    if (tracking_user_name_ == null) {
      return tracking_user_.getLogin();
    } else {
      return tracking_user_name_;
    }
  }

  @Override
  public Transport getTransport() {
    return transport_;
  }

}
